<?php
$tpl = <<< HTML
<tr id="sprice_{key}" data-ptype="{ptype}">
    <th>{inc}</th>
    <td class="td_date">
    从<input type="text" data-t="bt" name="ticket[{key}][bt]" {disabled} class="input-text w66" onfocus="SelectDate(this,'yyyy-MM-dd',0,0)" value="{bt}"/>至<input type="text" data-t="et" name="ticket[{key}][et]" {disabled} class="input-text w66" onfocus="SelectDate(this,'yyyy-MM-dd',0,0)" value="{et}"/></td>
    <td class="setDate">
        <a href="javascript:" class="date_chk" data-chk="1">全选</a>&nbsp;<a href="javascript:" class="date_chk" data-chk="2">平时</a>&nbsp;<a href="javascript:" class="date_chk" data-chk="3">周末</a>
        <br/>{week}
    </td>
    <td>
        <input type="text" data-t="pp" value="{storage}" {disabled} class="input-text w40 storage" name="ticket[{key}][storage]">
    </td>
    <td>
        <input type="text"  data-t="pp"  value="{pg}" {disabled} class="input-text w40 setnum_a" name="ticket[{key}][pg]">
    </td>
    <td>
       <input type="text"  data-t="sp"  value="{pl}" {disabled} class="input-text w40 setnum_b" name="ticket[{key}][pl]">
    </td>
    <td>
        {price_market}
    </td>
    <td>
        {key_index_del}
    </td>
</tr>
HTML;
$search_array = array(
    '{inc}',
    '{key}',
    '{ptype_select}',
    '{bt}',
    '{et}',
    '{week}',
    '{pg}',
    '{pl}',
    '{pm}',
    '{memo}',
    '{disabled}',
    '{key_index_del}',
    '{price_market}',
    '{storage}',
    '{ptype}'
);
$ptypeList = array('通用','节假日 ');
$tbl_html = '';
$price_market = isset($data['tprice'])?$data['tprice']*100/100:'';
if(!empty($isedit) && $_GET['act']!='copy'){
    $xml = $pobj->GetDynamicPrice('', 0, date('Y-m-d'),'',0);
    $lists = simplexml_load_string($xml);
    // print_r($lists);
    $key = -1;
    $inc = 0;
    $now = date('Y-m-d');
    foreach($lists->Rec as $val) {
        if((string)$val->UUend_date<$now || (int)$val->UUptype!=0) {
            continue;
        }
        $id = (int)$val->UUid;
        $ptype = (int)$val->UUptype;
        if(!empty($iscopy)) {
            $key --;
        }
        else {
            $key = $id;
        }
        $pg = $ptype==1 ? $val->UUs_price/100:$val->UUn_price/100;
        $storage = $val->UUstorage==-1 ? '不限': $val->UUstorage;
        $pl = $val->UUl_price/100;
        $inc += 1;
        $chkname = "ticket[{$key}][normalDay]";
        $selname = "ticket[$key][usedTime]";
        $ptype_select = GetHtmlSelect($ptypeList, $selname, $ptype,false,array('class'=>'pct','disabled'=>'disabled'));
        $ndList = explode(',', (string)$val->UUweekdays);
        $week = GetChkBox($WeekListShort,$chkname,$ndList,array('class'=>'pday','disabled'=>'disabled'));
        $memo = (string)$val->UUmemo ? $val->UUmemo : '';
        $key_index_del = '<a data-rid="'.$id.'" data-edit="1" class="remvPrice" href="javascript:">删除</a>';
        $key_index_del .= '&nbsp;<a data-rid="'.$id.'" class="editPrice" href="javascript:">编辑</a>';
        $price_market_str = $inc>1 ? '' :
            '<input type="text"  data-t="pm" '
                .'value="'.$price_market.'" disabled="disabled" class="input-text w40" '
                .'name="price1">';
        $replace_array = array(
            $inc,
            $key,
            $ptype_select,
            $val->UUstart_date,
            $val->UUend_date,
            $week,
            $pg,
            $pl,
            0,
            $memo,
            'disabled="diabled"',
            $key_index_del,
            $price_market_str,
            $storage,
            $val->UUptype
        );
            $tbl_html .= str_replace($search_array, $replace_array, $tpl);
        }
    $inc += 1;

    $tbl_html .= "<input type='hidden' id='key_index' value={$inc}/>";
}
else {
    $inc = 0;
    //$key_index_del = '1/<a data-rid="0" class="remvPrice" href="javascript:">删除</a>';
    $selname = "ticket[0][usedTime]";
    $chkname = "ticket[0][normalDay]";
    $ptype_select = GetHtmlSelect($ptypeList, $selname, $ptype,false,array('class'=>'pct'));
    $week = GetChkBox($WeekListShort,$chkname,array('0','1','2','3','4','5','6'),array('class'=>'pday'));
    $replace_array = array(
        1,
        $inc,
        $ptype_select,
        date('Y-m-d'),
        date('Y').'-12-31',
        $week,
        '',
        '',
        '',
        '',
        '',
        '<a data-rid="0" class="remvPrice" href="javascript:">删除</a>',
        '<span class="fn-rmb">￥</span><input type="text"  data-t="pm" value="" class="input-text w40" name="price1">',
        '不限',
        ''
    );
    $tbl_html .= str_replace($search_array, $replace_array, $tpl);
}
$week_js_name = 'ticket[{k}][normalDay]';
$week_js_tpl = GetChkBox($WeekListShort,$week_js_name,array('0','1','2','3','4','5','6'),array('class'=>'pday'));
echo $tbl_html;
?>
